<!--
 * @Description: 提醒录入 reminderEntry
 * @Autor: 刘诗文
 * @Date: 2020-12-31 13:58:38
 * @LastEditors: 马毅
 * @LastEditTime: 2021-06-29 13:47:54
-->
<template>
  <div>
    <FormPanel ref="formPanel" :list="formList" :cols="3" :labelWidth="130" :formType="type" :isSubmitBtn="false" />

    <!-- 提醒记录 -->
    <BaseDialog :visible.sync="showRemindRecordDialog" title="提醒记录" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <remindHistory :isSelectColumn="false" :remindId="formData.remindId" :remindSource="5"></remindHistory>
      <div class="dialogBottmView">
        <el-button @click="showRemindRecordDialog = false">返 回</el-button>
      </div>
    </BaseDialog>

    <div class="dialogBottmView">
      <el-button @click="cancelHandle">取 消</el-button>
      <AjaxButton type="primary" :click="saveHandle">确 定</AjaxButton>
    </div>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { isFormEmpty, notifyAction, camelCaseObject } from '@/utils';
import { saveVehicleRemind } from '@/api/customerRepair/customerCare/vehicleRemind';
import RemindHistory from '@/pages/customerRepair/customerCare/vehicleRemind/components/remindHistory.vue';

export default {
  name: 'reminderEntry',
  components: { RemindHistory },
  mixins: [dictionary],
  props: ['type', 'formData', 'remindSource'],
  data() {
    this.selectedData = null;
    return {
      formList: this.createFromList(),
      showRemindRecordDialog: false
    };
  },
  mounted() {
    console.log(this.formData);
  },
  methods: {
    createFromList() {
      return [
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'ownerName',
          disabled: true,
          initialValue: this.formData.ownerName
        },
        // {
        //   type: 'INPUT',
        //   label: '送修人',
        //   fieldName: 'deliverer',
        //   disabled: true,
        //   initialValue: this.formData.deliverer
        // },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'license',
          disabled: true,
          initialValue: this.formData.license
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin',
          disabled: true,
          initialValue: this.formData.vin
        },
        {
          type: 'INPUT',
          label: '车主电话',
          fieldName: 'phone',
          disabled: true,
          initialValue: this.formData.phone
        },
        // {
        //   type: 'INPUT',
        //   label: '送修人电话',
        //   fieldName: 'delivererPhone',
        //   disabled: true,
        //   initialValue: this.formData.delivererPhone
        // },
        {
          type: 'DATE',
          label: '保险到期日期',
          fieldName: 'insuranceExpirationDate',
          disabled: true,
          initialValue: this.formData.insuranceExpirationDate
        },
        {
          type: 'INPUT',
          label: '保险公司',
          fieldName: 'insuranceCompany',
          disabled: true,
          initialValue: this.formData.insuranceCompany,
          selfCols: 2
        },
        // {
        //   type: 'DATE',
        //   label: '本店最近购买保险日',
        //   fieldName: 'latestPurchaseDate',
        //   dateType: 'exactdate'
        // },
        {
          type: 'INPUT',
          labelWidth: '0',
          render: () => {
            return (
              <el-button
                type="primary"
                onClick={() => {
                  this.remindRecordBtnClick();
                }}
              >
                提醒记录
              </el-button>
            );
          }
        },
        {
          type: 'TEXT_AREA',
          label: '提醒内容',
          fieldName: 'remindContent',
          initialValue: '',
          selfCols: 3,
          rules: [{ required: true, message: '请填写提醒内容', trigger: 'blur' }]
        },
        {
          type: 'TEXT_AREA',
          label: '客户反馈',
          fieldName: 'customerFeedback',
          initialValue: '',
          selfCols: 3
          // rules: [{ required: true, message: '请填写提醒内容', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '提醒方式',
          fieldName: 'remindWay',
          itemList: this.createDictList(8081)
        },
        {
          type: 'SELECT',
          label: '提醒状态',
          fieldName: 'remindStatus',
          itemList: this.createDictList(8057),
          rules: [{ required: true, message: '请填写提醒状态', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '失败原因',
          fieldName: 'remindFailReason',
          itemList: this.createDictList(8069)
        },
        {
          type: 'DATE',
          label: '保险到期月',
          fieldName: 'insuranceMonth',
          initialValue: '',
          dateType: 'month'
        },
        {
          type: 'DATE',
          label: '保险到期日',
          fieldName: 'insuranceDay',
          dateType: 'exactdate'
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'remark',
          initialValue: '',
          selfCols: 3
        }
      ];
    },
    // 提醒记录点击
    remindRecordBtnClick() {
      this.showRemindRecordDialog = true;
    },
    async saveHandle() {
      const [err, data] = await this.$refs.formPanel.GET_FORM_DATA();
      if (err) return;
      data.remindType = this.remindSource;
      data.remindId = this.formData.remindId;
      data.ownerNo = this.formData.ownerNo;
      const res = await saveVehicleRemind({ ...data });
      if (res.resultCode === 200) {
        if (res.errMsg) {
          notifyAction(res.errMsg, 'error');
        } else {
          notifyAction('保存成功！');
          this.cancelHandle();
        }
      }
    },
    cancelHandle() {
      this.$emit('close', false);
    }
  }
};
</script>
<style lang="less" scoped></style>
